fix(nextjs): remove unnecessary csrfToken dependency from useCallback#54
fix(nextjs): remove unnecessary csrfToken dependency from useCallback#54
Conversation
Remove csrfToken from the secureFetch useCallback dependency array and drop the redundant newToken !== csrfToken comparison. React's setState already bails out for identical primitive values, so the equality check was unnecessary. The unstable function reference was causing the CsrfContextValue to change on every token update, triggering unwanted re-renders in downstream components. Fixes #53
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
WalkthroughA bug fix was implemented to reduce unnecessary re-renders in the CSRF context by removing Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Suggested labels
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
This PR addresses issue #53.
Problem
The React
secureFetchwrapper includedcsrfTokenin theuseCallbackdependency array. This caused the function reference to change every time a new token was received, which in turn madeCsrfContextValueunstable and triggered unnecessary re-renders in any component consuminguseCsrf().Solution
csrfTokenfrom the dependency array — the callback only needsconfigto remain stable.newToken !== csrfTokencheck — React'ssetStatealready bails out for identical primitive string values, so manual equality checking was unnecessary.Verification
pnpm --filter @csrf-armor/nextjs test→ 48 passedpnpm type-check→ cleanpnpm lint→ cleanChangeset
Patch bump for
@csrf-armor/nextjs.Fixes #53
Summary by CodeRabbit
Bug Fixes